﻿using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;

namespace WMS.Infrastructure
{
    /// <summary>
    /// 公共仓储
    /// </summary>
    public interface IBaseRepository<T> where T : class
    {
        /// <summary>
        /// 数据库上下类用于事务
        /// </summary>
        DbContext DbContext { get; set; }

        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        Task<IList<T>> GetAllAsync();

        /// <summary>
        /// 带参数查询所有数据
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<IList<T>> GetAllAsync(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<bool> InsertDataAsync(T entity);

        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<T> GetAsync(int id);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<bool> UpdateDataAsync(T entity);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(T entity);

        /// <summary>
        /// 获取单个对象（根据条件）
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<T> GetAsync(Expression<Func<T, bool>> expression);


        //----------------------------新封装的方法----------------------------
        /// <summary>
        /// 增加的方法
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        Task<int> AddNewAsync(T t);

        /// <summary>
        /// 获取大列表
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetNewAllList();

        /// <summary>
        /// 根据条件获取单个对象
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<T> GetNewValueAsync(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        Task<int> UpdateNewAsync(T t);

        /// <summary>
        /// 根据id查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<T> GetValueByIdAsync(int id);

        /// <summary>
        /// 根据id批量删除  真删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<int> DelDataAsync(Expression<Func<T, bool>> expression);


        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        Task<int> DelAll(List<T> list);
        
    }
}
